﻿/// You are given a text. Write a program that changes the text in all regions surrounded by the 
/// tags <upcase> and </upcase> to uppercase. The tags cannot be nested.
/// Example:
/// We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase> else.
/// The expected result:
/// We are living in a YELLOW SUBMARINE. We don't have ANYTHING else.


using System;
using System.Text.RegularExpressions;

class zad5
{
    static void Main()
    {
        string testText = @"We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase> else.";

        string tagName = "upcase";
        int startIndex = 0;
        for (int i = 0; i < testText.Length; i++)
        {
            if (testText[i] == '<')
            {
                startIndex = i;
                int startTagIndex;

                if ((startTagIndex = testText.IndexOf(tagName, i)) != -1)
                {
                    int wantedContentIndexStart = testText.IndexOf( '>', startTagIndex );
                    
                    int wantedContentIndexEnd = testText.IndexOf('<', wantedContentIndexStart);

                    int endTagIndex = testText.IndexOf('>', wantedContentIndexEnd);

                    string strToReplace = testText.Substring(wantedContentIndexStart + 1, wantedContentIndexEnd - wantedContentIndexStart - 1);
                   
                    // remove tags
                    testText = testText.Remove(i, endTagIndex-i+1);
                    
                    testText = testText.Insert(i , strToReplace.ToUpper());


                    i = wantedContentIndexEnd + 1;
                }
            }
        }

        Console.WriteLine(testText);
    }
}

